package com.info33.platform.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.system.dto.SysDeptDTO;
import com.info33.platform.system.entity.SysDept;
import com.info33.platform.system.service.SysDeptService;
import com.info33.platform.system.vo.SysDeptVO;
import com.info33.platform.system.vo.SysUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author admin
 */
@RestController
@RequestMapping("/SysDept")
@Api(tags = "系统 - 部门")
public class SysDeptController extends BaseController<SysDeptService, SysDept> {

    private final SysDeptService sysDeptService;

    @Autowired
    public SysDeptController(SysDeptService sysDeptService) {
        super(sysDeptService);
        this.sysDeptService = sysDeptService;
    }

    @DeleteMapping(value = "/pc/remove/{id}")
    @ApiOperation(value = "pc - 删除")
    public Result<Object> pcRemove(
            @PathVariable(value = "id") Long id) {
        return sysDeptService.pcRemove(id);
    }

    @PostMapping(value = "/pc/tree")
    @ApiOperation(value = "pc - 树结构")
    public Result<SysDeptVO> pcTree(
            @RequestBody SysDeptDTO dto) {
        SysUserVO currentUser = getCurrentUser();
        return sysDeptService.pcTree(dto, currentUser);
    }

    @GetMapping(value = "/pc/list/{ids}")
    @ApiOperation(value = "pc - 多字典查询", notes = "id 集合")
    public Result<List<SysDept>> pcList(
            @PathVariable(value = "ids") String ids) {
        return Result.ok(sysDeptService.list(new QueryWrapper<SysDept>().apply("FIND_IN_SET(id, {0}) > 0", ids)));
    }

}